package com.gzbit.calculator.ui;
/*1000以内的两个整数的加法和减法*/

import com.gzbit.calculator.bll.IOperation;
import com.gzbit.calculator.factory.AddFactory;
import com.gzbit.calculator.factory.IFactory;
import com.gzbit.calculator.factory.SubFactory;
import javafx.scene.Parent;

import java.util.Scanner;

class Parent {
    public final  int f1() {
        return 2;
    }
    public int f2() {
        return 2;
    }
}

class Son extends Parent {
    public int f1() {
        return super.f1() + 2;
    }
    public int f2() {
        return super.f1() + 2;
    }
}

/*
 * 作业2：
 * 1.解决上课中bll层的遗留问题
 * 2.使用泛型将Funs类中的函数浓缩为1个（同时实现整型、Float类型、Double类型数据的运算）
 * 3.方法：可使用泛型类型，也可以使用泛型函数
 * */
class Funs {
    public void IntegerCalculate() throws Exception {
        int numberA, numberB, result;
        String oprType;
        Scanner scanner = new Scanner(System.in);
        numberA = scanner.nextInt();
        numberB = scanner.nextInt();
        oprType = scanner.next();
        IOperation<Integer> opr = null;
        IFactory<Integer> factory = null;
        //根据运算符号去实例化工厂对象
        switch (oprType) {
            case "+":
                factory = new AddFactory<Integer>();
                break;
            case "-":
                factory = new SubFactory<Integer>();
                break;
            default:
                throw new Exception("输入的运算符号错误！");
        }
        //生产运算类对象
        opr = factory.getOperation();
        opr.setValue(numberA, numberB);
        result = opr.getResult();
        System.out.println(result);
    }

    public void FloatCalculate() throws Exception {
        float numberA, numberB, result;
        String oprType;
        Scanner scanner = new Scanner(System.in);
        numberA = scanner.nextFloat();
        numberB = scanner.nextFloat();
        oprType = scanner.next();
        IOperation<Float> opr = null;
        IFactory<Float> factory = null;
        //根据运算符号去实例化工厂对象
        switch (oprType) {
            case "+":
                factory = new AddFactory<Float>();
                break;
            case "-":
                factory = new SubFactory<>();
                break;
            default:
                throw new Exception("输入的运算符号错误！");
        }
        //生产运算类对象
        opr = factory.getOperation();
        opr.setValue(numberA, numberB);
        result = opr.getResult();
        System.out.println(result);
    }
}

public class Test {
    public static void main(String[] args) throws Exception {
    }
}

